package com.pp.web.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger 配置类
 * 访问地址: http://ip:port/swagger-ui.html
 * 此项目中访问地址: http://localhost:8090/swagger-ui.html
 * Swagger 的 baseUrl 配置: http://localhost:8090/api/
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            // 为当前包下 controllers 生成 API 文档
            .apis(RequestHandlerSelectors.basePackage("com.pp.web.controller"))
            // 排除
            // .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
            .paths(PathSelectors.any())
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("Pet Pleasure 宠趣社区 API 文档")
            .description("前端联调 RESTFul 接口")
            .version("v1.0")
            .contact(new Contact("Flora", "", "Flora <qih34@pitt.edu>"))
            .build();
    }
}
